package sws.alex.run;

import android.graphics.Bitmap;

public class Player extends Sprite {
	private int screenWidth, screenHeight;
	private int frameWidth, frameHeight;
	private boolean isAlive = false;
	
	public static final int UP = 1;
	public static final int DOWN = 2;
	public static final int LEFT = 3;
	public static final int RIGHT = 4;
	
	public static int SPEED = 4;
	
	public Player(Bitmap bitmap, int frameWidth, int frameHeight){
		super(bitmap);
		this.frameWidth = frameWidth;
		this.frameHeight = frameHeight;
		defineReferencePixel(frameWidth/2, frameHeight/2);
	}
	
	public void setScreenSize(int screenWidth, int screenHeight){
		this.screenWidth = screenWidth;
		this.screenHeight = screenHeight;
	}
	
	public void setAlive(boolean isAlive){
		this.isAlive = isAlive;
		setPosition(screenWidth/2, screenHeight/2);
	}
	
	public boolean getAlive(){
		return this.isAlive;
	}
	
	public void move(int direction){
		switch(direction){
		case UP:
			move(0, -SPEED);
			if(getY()<0) setPosition(getX(),0);
			break;
		case DOWN:
			move(0, SPEED);
			if(getY()>screenHeight-frameHeight) 
				setPosition(getX(), screenHeight-frameHeight);
			break;
		case LEFT:
			move(-SPEED,0);
			if(getX()<0) setPosition(0,getY());
			break;
		case RIGHT:
			move(SPEED,0);
			if(getX()>screenWidth-frameWidth)
				setPosition(screenWidth-frameWidth,getY());
			break;
		default:
			throw new IllegalArgumentException();
		}
	}
	
	public void init(){
		SPEED = 4;
		setAlive(true);
	}
	
}
